package com.hrt.datasender.datacollect.drive.weigeng;

import com.btcode.orm.executer.IORMExecuter;
import com.hrt.db.DBManager;

public final class BdDoorAccessService {

    private static volatile BdDoorAccessService instance;

    private BdDoorAccessService() {

    }

    public static BdDoorAccessService getInstance() {
        if (instance == null) {
            synchronized (BdDoorAccessService.class) {
                if (instance == null) {
                    instance = new BdDoorAccessService();
                }
            }
        }
        return instance;
    }

    public boolean create(BdDoorAccessModel model) {
        IORMExecuter executer = DBManager.getORMExecuter();
        String id = getId(model);

        BdDoorAccessModel tempModel = new BdDoorAccessModel();
        tempModel.setId(id);
        // 根据ID查询是否存在相同记录
        // 如果存在则不进行新增操作
        tempModel = executer.getModel(tempModel);
        if (tempModel != null) {
            return false;
        }

        executer.create(model);

        return true;
    }

    private String getId(BdDoorAccessModel value) {
        String id = value.getControlNo() + "_" + value.getCarNo() + "_" + value.getRecordDatetime() + "_"
                + value.getdoorMagnetism();
        return id;
    }

}